/*
 * File: Fu_Dummy_20ms.c
 *
 * Code generated for Simulink model 'Fu_Dummy_20ms'.
 *
 * Model version                  : 1.407
 * Simulink Coder version         : 8.2 (R2012a) 29-Dec-2011
 * TLC version                    : 8.2 (Dec 29 2011)
 * C/C++ source code generated on : Sat Jun 15 20:12:22 2013
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: ARM Compatible->ARM Cortex
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "Fu_Dummy_20ms.h"
#include "Fu_Dummy_20ms_private.h"

/* Named constants for Chart: '<S3>/Chart' */
#define Fu_Dummy_20ms_IN_Off           ((uint8_T)1U)
#define Fu_Dummy_20ms_IN_On            ((uint8_T)2U)

/* Exported block signals */
uint16_T Net_Volt48;                   /* '<S1>/Constant' */
int16_T Emi_CurDReq;                   /* '<S1>/Constant2' */
uint8_T CodFoc_ElecPolNr;              /* '<S1>/Constant3' */
boolean_T FuDummy_FlgLed2;             /* '<S1>/Constant1' */
boolean_T FuDummy_FlgLed1;             /* '<S3>/Chart' */

/* Block states (auto storage) */
D_Work_Fu_Dummy_20ms Fu_Dummy_20ms_DWork;

/* Real-time model */
RT_MODEL_Fu_Dummy_20ms Fu_Dummy_20ms_M_;
RT_MODEL_Fu_Dummy_20ms *const Fu_Dummy_20ms_M = &Fu_Dummy_20ms_M_;

/* Model step function */
void Fu_Dummy_20ms_step(void)
{
  int32_T tmp;
  int32_T tmp_0;

  /* Chart: '<S3>/Chart' incorporates:
   *  UnitDelay: '<S2>/Unit Delay'
   */
  /* Gateway: Logic Operation/TurnOffDelay_V2/Chart */
  /* During: Logic Operation/TurnOffDelay_V2/Chart */
  if (Fu_Dummy_20ms_DWork.is_active_c3_Autocoding_Library == 0) {
    /* Entry: Logic Operation/TurnOffDelay_V2/Chart */
    Fu_Dummy_20ms_DWork.is_active_c3_Autocoding_Library = 1U;

    /* Entry Internal: Logic Operation/TurnOffDelay_V2/Chart */
    /* Transition: '<S4>:31' */
    FuDummy_FlgLed1 = Fu_Dummy_20ms_DWork.UnitDelay_DSTATE;
    if (Fu_Dummy_20ms_DWork.UnitDelay_DSTATE) {
      /* Transition: '<S4>:30' */
      Fu_Dummy_20ms_DWork.is_c3_Autocoding_Library_Xu = Fu_Dummy_20ms_IN_On;

      /* Entry Internal 'On': '<S4>:8' */
      /* Transition: '<S4>:19' */
      if (!Fu_Dummy_20ms_DWork.UnitDelay_DSTATE) {
        /* Transition: '<S4>:17' */
        tmp = Fu_Dummy_20ms_DWork.loc_Clock * 13107 >> 14;
        tmp_0 = tmp + 16;
        if ((tmp > 0) && (tmp_0 <= 0)) {
          tmp_0 = MAX_int32_T;
        }

        tmp = mul_s32_s32_s32_sr2_sat(tmp_0, 5);
        if (tmp > 32767) {
          tmp = 32767;
        } else {
          if (tmp < -32768) {
            tmp = -32768;
          }
        }

        Fu_Dummy_20ms_DWork.loc_Clock = (int16_T)tmp;
      } else {
        /* Transition: '<S4>:18' */
        Fu_Dummy_20ms_DWork.loc_Clock = 0;
      }
    } else {
      /* Transition: '<S4>:29' */
      Fu_Dummy_20ms_DWork.is_c3_Autocoding_Library_Xu = Fu_Dummy_20ms_IN_Off;
    }
  } else if (Fu_Dummy_20ms_DWork.is_c3_Autocoding_Library_Xu ==
             Fu_Dummy_20ms_IN_Off) {
    /* During 'Off': '<S4>:7' */
    if (Fu_Dummy_20ms_DWork.UnitDelay_DSTATE) {
      /* Transition: '<S4>:10' */
      FuDummy_FlgLed1 = TRUE;
      Fu_Dummy_20ms_DWork.loc_Clock = 0;
      Fu_Dummy_20ms_DWork.is_c3_Autocoding_Library_Xu = Fu_Dummy_20ms_IN_On;

      /* Entry Internal 'On': '<S4>:8' */
      /* Transition: '<S4>:19' */
      if (!Fu_Dummy_20ms_DWork.UnitDelay_DSTATE) {
        /* Transition: '<S4>:17' */
        tmp = Fu_Dummy_20ms_DWork.loc_Clock * 13107 >> 14;
        tmp_0 = tmp + 16;
        if ((tmp > 0) && (tmp_0 <= 0)) {
          tmp_0 = MAX_int32_T;
        }

        tmp = mul_s32_s32_s32_sr2_sat(tmp_0, 5);
        if (tmp > 32767) {
          tmp = 32767;
        } else {
          if (tmp < -32768) {
            tmp = -32768;
          }
        }

        Fu_Dummy_20ms_DWork.loc_Clock = (int16_T)tmp;
      } else {
        /* Transition: '<S4>:18' */
      }
    }
  } else {
    /* During 'On': '<S4>:8' */
    if (((!Fu_Dummy_20ms_DWork.UnitDelay_DSTATE) &&
         ((Fu_Dummy_20ms_DWork.loc_Clock * 13107 >> 2) >= 16384000)) ||
        ((!Fu_Dummy_20ms_DWork.UnitDelay_DSTATE) &&
         Fu_Dummy_20ms_DWork.UnitDelay_DSTATE)) {
      /* Transition: '<S4>:24' */
      /* Transition: '<S4>:25' */
      /* Transition: '<S4>:26' */
      FuDummy_FlgLed1 = FALSE;
      Fu_Dummy_20ms_DWork.is_c3_Autocoding_Library_Xu = Fu_Dummy_20ms_IN_Off;
    } else {
      /* Transition: '<S4>:21' */
      Fu_Dummy_20ms_DWork.is_c3_Autocoding_Library_Xu = Fu_Dummy_20ms_IN_On;

      /* Entry Internal 'On': '<S4>:8' */
      /* Transition: '<S4>:19' */
      if (!Fu_Dummy_20ms_DWork.UnitDelay_DSTATE) {
        /* Transition: '<S4>:17' */
        tmp = Fu_Dummy_20ms_DWork.loc_Clock * 13107 >> 14;
        tmp_0 = tmp + 16;
        if ((tmp > 0) && (tmp_0 <= 0)) {
          tmp_0 = MAX_int32_T;
        }

        tmp = mul_s32_s32_s32_sr2_sat(tmp_0, 5);
        if (tmp > 32767) {
          tmp = 32767;
        } else {
          if (tmp < -32768) {
            tmp = -32768;
          }
        }

        Fu_Dummy_20ms_DWork.loc_Clock = (int16_T)tmp;
      } else {
        /* Transition: '<S4>:18' */
        Fu_Dummy_20ms_DWork.loc_Clock = 0;
      }
    }
  }

  /* End of Chart: '<S3>/Chart' */

  /* Update for UnitDelay: '<S2>/Unit Delay' incorporates:
   *  Constant: '<S2>/Constant'
   */
  Fu_Dummy_20ms_DWork.UnitDelay_DSTATE = FALSE;
}

/* Model initialize function */
void Fu_Dummy_20ms_initialize(void)
{
  /* Registration code */

  /* initialize error status */
  rtmSetErrorStatus(Fu_Dummy_20ms_M, (NULL));

  /* block I/O */

  /* exported global signals */
  Net_Volt48 = 1400U;
  Emi_CurDReq = 0;
  CodFoc_ElecPolNr = ((uint8_T)3U);
  FuDummy_FlgLed2 = FALSE;
  FuDummy_FlgLed1 = FALSE;

  /* states (dwork) */
  (void) memset((void *)&Fu_Dummy_20ms_DWork, 0,
                sizeof(D_Work_Fu_Dummy_20ms));

  /* ConstCode for Constant: '<S1>/Constant' */
  Net_Volt48 = 1400U;

  /* ConstCode for Constant: '<S1>/Constant2' */
  Emi_CurDReq = 0;

  /* ConstCode for Constant: '<S1>/Constant3' */
  CodFoc_ElecPolNr = 3U;

  /* ConstCode for Constant: '<S1>/Constant1' */
  FuDummy_FlgLed2 = FALSE;

  /* InitializeConditions for UnitDelay: '<S2>/Unit Delay' */
  Fu_Dummy_20ms_DWork.UnitDelay_DSTATE = TRUE;

  /* InitializeConditions for Chart: '<S3>/Chart' */
  Fu_Dummy_20ms_DWork.is_active_c3_Autocoding_Library = 0U;
  Fu_Dummy_20ms_DWork.is_c3_Autocoding_Library_Xu = 0U;
  Fu_Dummy_20ms_DWork.loc_Clock = 0;
  FuDummy_FlgLed1 = FALSE;
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
